package com.yuan.cmn;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * @Author yuan
 * @Date 2021/7/12 14:52
 */
@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan(basePackages = "com.yuan")
@Slf4j
public class ServiceCmnApplication {
    public static void main(String[] args) {
        try {
            ConfigurableApplicationContext application = SpringApplication.run(ServiceCmnApplication.class, args);
            Environment env = application.getEnvironment();
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String path = env.getProperty("server.servlet.context-path");
            if (StringUtils.isEmpty(path)) {
                path = "";
            }
            log.info("\n----------------------------------------------------------\n\t" +
                    "Application Hospital is running! Access URLs:\n\t" +
                    "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                    "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                    "Swagger文档: http://" + ip + ":" + port + path + "/doc.html\n" +
                    "----------------------------------------------------------");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
